import { getIndexList, getHotList, getNewList } from '../../api/index'
export default {
  namespaced: true,
  state: {
    indexBanner: [],
    hot:[],
    news:[],
    page:1,
    limit:10,
    total:0,
    indexAll:{}
  },
  mutations: {
    updateBanner(state, payload) {
      // console.log(1)
      state.indexBanner = payload
    },
    updateHot(state, payload) {
      // console.log(1)
      state.hot = payload
    },
    updateNews(state, payload) {
      // console.log(1)
      state.news.push(...payload)
    },
    updatePage(state,){
      // state.page +=1
      state
    },
    updateTotal(state,payload){
      state.total = payload
    },
    updateIndexAll(state,payload){
      state.indexAll = payload
    }
  },
  actions: {
    async getBannerList(context) {
      try {
        const res = await getIndexList()
        // console.log(res)
        // console.log(res.data.showBanner)
        // console.log(res.errno);
        if (res.errno === 0) {
          context.commit('updateBanner', res.data.banner)
          context.commit('updateIndexAll', res.data)
        
        }
      } catch (error) {
        //
      }
    },
    async getHotList(context) {
      try {
        const res = await getHotList()
        // console.log(res)
        // console.log(res.data.showBanner)
        // console.log(res.errno);
        if (res.errno === 0) {
          context.commit('updateHot', res.data.list)
        }
        return res.data.list
      } catch (error) {
        //
      }
     
    },
    async getNewList(context) {
      try {
        const res = await getNewList({page:context.state.page,limit:context.state.limit})
        console.log(res)
       
        // console.log(res.errno);
        if (res.errno === 0) {
          context.commit('updateNews', res.data.list.data)
          context.commit('updateTotal', res.data.list.count)
        }
      } catch (error) {
        //
      }
    }
  },
  getters: {}
}
